from typing import Optional

from model.uml_element import UmlElement
from model.uml_extension_end import UmlExtensionEnd
from model.uml_xmi_info import UmlXmiInfo


class UmlExtension(UmlElement):
    def __init__(self) -> None:
        super().__init__(UmlXmiInfo.type_extension)
        self.name: str = ""
        self.memberEnd: str = ""
        self.ownedEnd: Optional[UmlExtensionEnd] = None

    def to_json(self) -> dict[str, object]:
        json: dict = super().to_json()
        json["name"] = self.name
        json["memberEnd"] = self.memberEnd

        if self.ownedEnd is not None:
            json["ownedEnd"] = self.ownedEnd.to_json()

        return json
